import { AxiosResponse } from "axios";
import { saveAs } from "file-saver";

export function saveAsExcel(response: AxiosResponse, fileName?: string) {
  const fileType =
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8";
  if (!fileName) {
    fileName = decodeURI(response.headers["content-disposition"].split(";")[1].split("=")[1]);
  }
  const blob = new Blob([response.data], { type: fileType });
  saveAs(blob, fileName);
}
